<?php
namespace Jammiest\SwigeCore\Console\Commands\Server;

use Symfony\Component\Console\Attribute\AsCommand;
use Jammiest\SwigeCore\Console\Commands\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

#[AsCommand(
    name: 'server:restart',
    description: '重启 Swoole 服务器'
)]
class RestartCommand extends Command
{
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $stopCommand = $this->getApplication()->find('server:stop');
        $startCommand = $this->getApplication()->find('server:start');

        $stopCommand->run($input, $output);
        sleep(2); // 等待服务器完全停止
        $startCommand->run($input, $output);

        return Command::SUCCESS;
    }
}